require(['grid', 'topBar', 'layout', 'date'], function () {
	var $logUploadBtn=$("#logUploadBtn"),$grid = $('#grid'),
		$logSearchBtn=$("#logSearchBtn");

	//grid初始化
	function gridInit() {
		$grid.grid({
			url: "/upgrade/searchDevLogUploadPage.htm",
			multiselect: false,
			colModel:[
				{name: "rcrdId",index : "rcrdId",hidden : true},
				{name: "licPltNo", label: "车牌号"},
				{name: "eqmtCd", label: "设备ID"},
				{name: "upgradeBeginTime", label: "下发开始时间"},
				{name: "upgradeEndTime", label: "上传结束时间"},
				{name: "upgradeSt", label: "上传状态"},
				{name: "stMsg", label: "状态消息"},
				{name: "eqmtLogName", label: "文件名"},
				{name: "upgradeUser", label: "下发人"}
			],
			showPaper: true,
			height:$(window).height()-60
		});
	}

	$logSearchBtn.on("click", function(){
		var selectedNodes  = commonFun.getLeftTreeSelectedNodes();
		if (!selectedNodes.length) {
			$.messager.alert("提示", "请先选择左侧树的一辆车辆!", "warning");
			return;
		} else {
			if (selectedNodes[0].type !== "CAR") {
				$.messager.alert("提示", "请先选择左侧树的一辆车辆!", "warning");
				return ;
			}
		}
	//	if (date) {
			$grid.grid('setGridParam', {
				datatype: "json",
				postData: {
					"carId" : selectedNodes[0].id,
					"reportDate" :$("#reportDate1").val()
				}
			}).trigger("reloadGrid");
		//}
	});

	/* 事件绑定 */
	$logUploadBtn.on("click", function(){
		var selectedNodes;
		selectedNodes = commonFun.getLeftTreeSelectedNodes();
		if (!selectedNodes.length) {
			$.messager.alert("提示", "请先选择左侧树的一辆车辆!", "warning");
			return;
		} else {
			if (selectedNodes[0].type !== "CAR") {
				$.messager.alert("提示", "请先选择左侧树的一辆车辆!", "warning");
				return ;
			}
		}
		if(!$("#reportDate1").val()){
			$.messager.alert("提示", "请先选择日期", "warning");
			return;
		}
		$.ajaxExt({
			url : "/upgrade/devLogUpload.htm",
			data : {
				"carId" : selectedNodes[0].id,
				"reportDate" :$("#reportDate1").val()
			}
		}).done(function(result){

		});
	});

	var now = new Date ();
	var year = now.getFullYear ();//获取四位数年数
	var month = now.getMonth () + 1;
	var date = now.getDate ();
	var weeknum = now.getDay ();
	var str = year + "-" + Appendzero (month) + "-" + Appendzero (date);
	$('#reportDate1').val(str);
	function Appendzero (obj) {
		if (obj < 10) {
			return "0" + obj;
		}else{
			return obj;
		}
	}

	$('body').layout();
	//初始化grid
	gridInit();
});
